<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        Promise.prototype.myFinally = function (cb) {//cb就是要共同执行的逻辑
            return this.then(//谁调用finally，this就是谁
                value => Promise.resolve(cb()),//不管调用finally的promise是什么状态都会执行这个cb
                error =>//不管调用finally的promise是什么状态都会执行这个cb
                    Promise.resolve(cb())
            );
        };
        let p2 = new Promise((resolve, reject) => resolve(2));
        p2.finally(() => {
            console.log("finally");
        })
        p2.myFinally(() => {
            console.log("myFinally");
        })
    </script>
</body>

</html>